package com.example.controller;

import com.example.common.Result;
import com.example.entity.GameInfo;
import com.example.service.GameInfoService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/gameInfo")
public class GameInfoController {

    @Autowired
    GameInfoService gameInfoService;

    /**
     * 新增
     */

    @PostMapping("/add")
    public Result add (@RequestBody GameInfo gameInfo){
        gameInfoService.add(gameInfo);
        return Result.success();
    }

    /**
     * 删除
     */

    @DeleteMapping("/delete/{id}")
    public Result delete (@PathVariable Integer id){
        gameInfoService.deleteById(id);
        return Result.success();
    }
    /**
     * 更新
     */

    @PutMapping("/update")
    public  Result update (@RequestBody GameInfo gameInfo)
    {
        gameInfoService.updateById(gameInfo);
        return Result.success();
    }
    /**
     * 列表
     */

    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10")Integer pageSize,
                            Integer gameId, String gameName, String gameType){
        PageInfo<GameInfo> PageInfo = gameInfoService.selectPage(pageNum,pageSize, gameId,gameName,gameType);
        return Result.success(PageInfo);
    }


}
